<template>
  <div class="notice" v-if="msgMode.list.length > 0">
    <image class="title" src="./images/ptkx.png" />
    <div class="bar"></div>
    <div class="message">
      <wd-notice-bar
        custom-class="notice-bar"
        :text="msgMode.list.map((_) => _.title)"
        direction="vertical"
        color="#5c6066"
        background-color="#fff"
        @next="nextChange"
        @click="clickNotice"
      >
        <template #prefix>
          <div class="tag" v-if="msgMode.currentType === '1'">公告</div>
          <div class="tag activity" v-if="msgMode.currentType === '2'">活动</div>
          <!-- <div class="tag dt" v-if="msgMode.currentType === 2">动态</div> -->
        </template>
      </wd-notice-bar>
    </div>
    <span class="icon i-carbon-chevron-right"></span>
  </div>
</template>
<script lang="ts" setup>
import { to } from '@/utils/page'
defineOptions({
  name: 'Notice',
})

const msgMode = reactive({
  list: [],
  currentType: '',
})
http.get('/notice-app/open/list').then((res: any) => {
  msgMode.list = res
  if (res.length > 0) {
    msgMode.currentType = msgMode.list[0].type
  }
})

function nextChange(index) {
  msgMode.currentType = msgMode.list[index].type
}

function clickNotice(item) {
  to('/pages-sub/system/notice', { id: msgMode.list[item.index].id })
}
</script>
<style lang="scss" scoped>
.notice {
  display: flex;
  align-items: center;
  height: 96rpx;
  padding: 0 20rpx;
  margin: 0 32rpx;
  box-shadow: inset 0px -0.5px 0px #dfe3e6;
  .title {
    width: 50rpx;
    height: 53rpx;
  }
  .bar {
    width: 1rpx;
    height: 40rpx;
    margin: 0 20rpx;
    background-color: #ebeef0;
  }
  .message {
    flex: 1;
    width: 0;
    .notice-bar {
      padding-right: 0;
      padding-left: 0;
    }
  }
  .icon {
    margin-left: 6rpx;
    font-size: 36rpx;
    color: #8a8f99;
  }
  .tag {
    box-sizing: border-box;
    width: 58rpx;
    height: 38rpx;
    margin-right: 20rpx;
    font-size: 20rpx;
    line-height: 34rpx;
    color: #07c160;
    text-align: center;
    border: 1rpx solid #07c160;
    border-radius: 10rpx;
    &.activity {
      color: #ffaa00;
      border-color: #ffaa00;
    }
    &.dt {
      color: #337cee;
      border-color: #337cee;
    }
  }
}
</style>
